$(document).ajaxError(function (evt, request, settings) {
    if (request.responseText.indexOf('loginForm') != -1)
        location.href = "/login";
});

bootbox.setDefaults("locale", "zh_CN");

var makeValidateErrors =
    function (form, errors) {
        if (errors !== undefined && errors instanceof Array) {
            form.find('#message').find("#message-panel").remove();

            var $panel = $('<div id="message-panel" class="panel panel-danger"><div class="panel-heading">' + '提交失败' + '</div><div class="panel-body"></div></div>')
                .appendTo(form.find('#message'));
            $('<dl class="dl-horizontal"></dl>').appendTo($panel.find(".panel-body"));
            errors.forEach(function (error) {
                var $ele = form.find("#" + error.field);
                $ele.closest('.form-group').removeClass('has-success').addClass('has-error');

                $('<dt class="text-danger">' + ($ele.attr("placeholder") == null ? "异常:" : $ele.attr("placeholder")) +
                    '</dt><dd>' + error.defaultMessage + '</dd>')

                    .appendTo(form.find("dl"));
            })
        }

    }